<?php
Junction_FileCabinet::package("Junction_Utils_Reflection");
Junction_FileCabinet::package("Junction_Utils");
Junction_FileCabinet::using("Junction_Resources_Catalog");
Junction_FileCabinet::using("Test_Mock_Client");

class Test_Junction_Utils_Reflection_Facade extends UnitTestCase {
	
	public function testCreate() {
		$stack = Junction_Utils_Reflection_Facade::getInstance("Junction_Utils_Stack", array());
		$this->assertTrue(is_a($stack, "Junction_Utils_Stack"));
		$file = Junction_Utils_Reflection_Facade::getInstance("Junction_Utils_IO_File", 
			array(Junction_Resources_Catalog::fetch("Catalog.php")));
		$this->assertTrue(is_a($file, "Junction_Utils_IO_File"));
	}
	
	public function testInvalidCreate() {
		try {
			$stack = new Junction_Utils_Stack();
			Junction_Utils_Reflection_Facade::getInstance("Junction_Utils_Stack", array(1, 3, 4));
		} catch (Junction_Utils_Reflection_Exception $e) {
			$this->pass();
		} catch (Exception $e) {
			$this->fail();
		}
	}
	
	public function testInvoke() {
		$stack = new Junction_Utils_Stack();
		Junction_Utils_Reflection_Facade::invokeArgs($stack, "push", array("foobar"));
		$this->assertTrue($stack->pop() == "foobar");
	}
	
	public function testInvalidInvoke() {
		try {
			$stack = new Junction_Utils_Stack();
			Junction_Utils_Reflection_Facade::invokeArgs($stack, "push", array());
			Junction_Utils_Reflection_Facade::invokeArgs($stack, "push", array(1, 2, 3));	
		} catch (Junction_Utils_Reflection_Exception $e) {
			$this->pass();
		} catch (Exception $e) {
			$this->fail();
		}
	}
}
?>